<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>驴妈妈统计系统</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.css" />
<link rel="stylesheet"
	href="${request.contextPath}/static/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery.gritter.min.css" />
<!-- text fonts -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace.min.css"
	class="ace-main-stylesheet" id="main-ace-style" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="${request.contextPath}/static/stylesheets/daterangepicker.css">
<script src="${request.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
<!-- ace settings handler -->
<script src="${request.contextPath}/static/assets/js/ace-extra.min.js"></script>
</head>
<body class="no-skin" style="background-color: #FFF;">
	<div class="page-content" style="padding: 2px 2px 0px;">
	 	<div class="tabbable">
			<div class="tab-content">
		 		<div id="manage" class="tab-pane active in">
		 		<!-- 筛选条件开始 -->
					<div class="row">
						<div class="col-sm-12">
							<div class="widget-box">
								<div class="widget-body" style="background-color: #EFF3F8;">
									<div class="widget-main">
									<form class="form-inline" id="searchForm" method="post"
										action="${request.contextPath}/backJobConfig/jobList">
										<input type="hidden" id="_csrf" name="${_csrf.parameterName}"
											value="${_csrf.token}" />	
										<div class="form-group">
											<label for="exampleInputName2">任务编码 <input class="form-control" name="jobCodeVO"
												placeholder="任务编码" type="text" value="${jobListConditionVO.jobCodeVO!}" style="width:120px">
											</label>
											<label for="exampleInputName" style="margin-left: 30px;">任务名称 <input class="form-control"
												name="jobNameVO" placeholder="任务名称" type="text" value="${jobListConditionVO.jobNameVO!}" style="width:120px">
											</label>
											<button type="submit" class="btn btn-pink btn-sm" id="search" for="exampleInputName" style="margin-left: 30px;">
												<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
												查询
											</button>
											<!-- <a class="btn btn-pink btn-sm" for="exampleInputName" style="margin-left: 30px;">
												<span class="ace-icon fa icon-on-right bigger-110"></span>
												新增
											</a> -->
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- 筛选条件结束 -->
				<!-- tab开始 -->
				<div class="row">
					 <div class="col-sm-12">
						<div class=" widget-box" style="border:none;">
								<table id="dynamic-table"
									class="table table-striped table-bordered table-hover dataTable no-footer"
									role="grid" aria-describedby="dynamic-table_info">	
									<thead>
										<tr>
											<th>No.</th>
											<th>任务编码</th>
											<th>任务序列</th>
											<th>任务名称</th>
											<th>执行方式</th>
							<!-- 				<th>任务处理类</th> -->
											<th>任务参数</th>
											<th>任务周期</th>
											<th>配置是否有效</th>
									<!-- 		<th>最大重执行次数</th> -->
											<th>子任务详情</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
									 	<#if jobVOList?? && jobVOList?size&gt;0> 
										      	<#list  jobVOList as jobVO>
												<tr class="">
												    <td>${jobVO.jobconfig_id!}</td>
												    <td>${jobVO.job_code!}</td>
													<td>${jobVO.job_seq!}</td>
												    <td>${jobVO.job_name!}</td>
												    <td>
												       <#if jobVO.exec_mode =="0">
												                     周期执行
												       <#else>
												                     非周期执行 
                                                       </#if>   
												    </td>
													<!-- <td>${jobVO.job_classname!}</td> -->
													<td>${jobVO.job_param!}</td>
												    <td>${jobVO.job_cron!}</td>
													<td>
													 <#if jobVO.job_valid ==1>
												                       有效
												     <#else>
												                     无效 
                                                     </#if>   
													</td>
													<!-- <td>${jobVO.retry_num!}</td>		 -->										
											<td class="center">
												<div class="action-buttons">
													<a href="#" class="green bigger-140 show-details-btn"
														title="Show Details" onclick="showDetails('${jobVO.job_code!}')"> <i
														class="ace-icon fa fa-angle-double-down"></i> <span
														class="sr-only">Details</span>
													</a>
												</div>
											</td>
											<td>
												<div class="hidden-sm hidden-xs action-buttons"
													align="right">
													<a title="新增子任务" class="green" href="#"
														onclick="openModel('child','${jobVO.job_code!}');"> <i
														class="ace-icon fa fa-search-plus bigger-130"></i>
													</a> <a title="编辑" class="green" href="#"
														onclick="updateJob('${jobVO.jobconfig_id!}');" role="button"
														data-target="#myModal" data-toggle="modal"> <i
														class="ace-icon fa fa-pencil bigger-130"></i>
													</a> <a title="删除" class="red" onClick="deleteJobConfig('${jobVO.jobconfig_id!}')"> 
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
													</a>
												</div>
											</td>
										</tr>
										<tbody class="detail-row" data-show=“1” style='display: none'
										align='center' id="${jobVO.job_code!}">
									</tbody>
									   </#list> <#else>
										<tr>
											<td colspan="12">
												<div class="alert alert-danger" style="margin-bottom: 0px;"
													role="alert">没有记录!</div>
											</td>
										</tr>
									  </#if>
									</tbody>
								</table>
								<#include "/paginator.html">
							</div>
						</div>
					</div>
					<!-- tab结束-->
				</div>
				<div class="row">
					<div class="col-xs-12">
						<button class="btn btn-info" data-toggle="modal" type="button"
							style="display: none;" id="update" data-target="#myModal">
						</button>
						<form  class="form-horizontal" role="form" id="searchForm" method="post"
										action="${request.contextPath}/backJobConfig/jobUpdate">
							<input type="hidden" id="_csrf" name="${_csrf.parameterName}"
											value="${_csrf.token}" />
							<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
								aria-labelledby="myModalLabel" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal"
												aria-hidden="true">×</button>
											<h4 class="modal-title" id="myModalLabel">job配置</h4>
										</div>
										<div class="modal-body">
											<input id="jobconfig_id" name="jobconfig_id" value="" type="hidden">
											<div class="space-4"></div>
											<div class="form-group">
												<div class="col-sm-9">
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 系统代码 </label>

														<div class="col-sm-9">
															<input type="text" id="syscode" name="syscode" placeholder="系统代码"
																class="form-control" required="required" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务编码 </label>

														<div class="col-sm-9">
															<input type="text" id="job_code" name="job_code" placeholder="任务编码"
																class="form-control" required="required" readonly>
														</div>
													</div>
													<div class="form-group" id="childCode">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 子任务编码 </label>

														<div class="col-sm-9">
															<input type="text" id="sub_job_code" name="sub_job_code" placeholder="子任务编码"
																class="form-control" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务类型</label>

														<div class="col-sm-9">
														   <select name="job_type" id="job_type" aria-controls="dynamic-table" class="form-control input-sm" readonly>
															    <option  value="0" >主任务</option>
															    <option  value="1" >子任务</option>
														   </select>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务序列 </label>

														<div class="col-sm-9">
															<input type="text" id="job_seq" name="job_seq" placeholder="任务序列"
																class="form-control" required="required" readonly>
														</div>
													</div>
											
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务名称</label>

														<div class="col-sm-9">
															<input type="text" id="job_name" name="job_name"
																placeholder="任务名称" class="form-control" required="required" readonly>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 执行方式</label>

														<div class="col-sm-9">
														 <select name="exec_mode" id="exec_mode" aria-controls="dynamic-table" class="form-control input-sm" readonly>
															    <option  value="0" >周期执行</option>
															    <option  value="1" >非周期执行</option>  
														  </select>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">任务处理类</label>

														<div class="col-sm-9">
															<input type="text" id="job_classname" name="job_classname"
																placeholder="任务处理类" class="form-control" required="required" >
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务参数</label>

														<div class="col-sm-9">
															<input type="text" id="job_param" name="job_param"
																placeholder="任务参数" class="form-control" required="required">
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 任务周期</label>

														<div class="col-sm-9">
															<input type="text" id="job_cron" name="job_cron"
																placeholder="任务周期" class="form-control" required="required">
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1">配置是否有效</label>

														<div class="col-sm-9">
														 <select name="job_valid" id="job_valid" aria-controls="dynamic-table" class="form-control input-sm">
															    <option  value="0" >有效</option>
															    <option  value="1" >无效</option>  
														  </select>
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 最大重执行次数</label>

														<div class="col-sm-9">
															<input type="text" id="retry_num" name="retry_num"
																placeholder="最大重执行次数" class="form-control">
														</div>
													</div>
													<div class="form-group">
														<label class="col-sm-3 control-label no-padding-right"
															for="form-field-1"> 转换重试最大次数</label>

														<div class="col-sm-9">
															<input type="text" id="convert_retry_num" name="convert_retry_num"
																placeholder="转换重试最大次数" class="form-control">
														</div>
													</div>
													
												</div>
											</div>
										</div>
										<div class="modal-footer">
											<button type="button" class="btn btn-default"
												data-dismiss="modal">关闭</button>
											<button  type="submit" class="btn btn-primary">
												提交</button>
										</div>
									</div>
									<!-- /.modal-content -->
								</div>
								<!-- /.modal -->
							</div>
						</form>
					</div>
				</div>



			</div>
		</div>
	</div>
    <input type="hidden" id="joblistcontext" value="${request.contextPath}"/>
	<script src="${request.contextPath}/static/assets/js/bootstrap.min.js"></script>
	<!-- page specific plugin scripts -->
	<script src="${request.contextPath}/static/assets/js/jquery-ui.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/jquery.gritter.min.js"></script>
	<!-- ace scripts -->
	<script src="${request.contextPath}/static/assets/js/ace-elements.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/ace.min.js"></script>
	<script src="${request.contextPath}/static/assets/js/bootbox.js"></script>
	<!-- user scripts -->
	<script src="${request.contextPath}/static/assets/js/user/base.js"></script>
	<script type="text/javascript" src="${request.contextPath}/static/javascripts/moment.js"></script>
	<script type="text/javascript" src="${request.contextPath}/static/javascripts/daterangepicker.js"></script>
	<script type="text/javascript">
	var joblistcontext = $("#joblistcontext").val();
	jQuery(function($) {		
		
		/***************/
		$('.show-details-btn').on('click', function(e) {
			e.preventDefault();
			$(this).closest('tbody').next().toggle()
			$(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-up');
		});
		
		
		
	})
	
	
		function openModel(type,code){
			if(type=="super"){
				$('#myModal').find("input").val("");
				$("#childCode").hide();
				$('#job_type').find("option[value=0]").attr("selected",true);
			}else{
				$("#childCode").show();
				$('#myModal').find("input").val("");
				$('#job_type').find("option[value=1]").attr("selected",true);
				$("#job_code").val(code);
				
			}
			$('#myModal').find("input").removeAttr("readOnly");
			$('#myModal').find("select").removeAttr("readOnly");
			$("#myModal").modal("show");
			
		}
		
		function showDetails(job_code){
			  $.ajax({
					url : joblistcontext+'/backJobConfig/showDetails?job_code='+job_code,
					type : "GET",
					success:function(data) {
						console.log(data);
						if(data.sessionStatus==540){//异步请求session过期状态
							window.location.href=joblistcontext+"/login";
							//location.href="show_product?prodId="+prod_id+"&sceneryName="+tdSceneryName+"&pageNum="+$("#pageNum").val();
						}else if(data.code=1){
							
						   var jobChildsList = data.jobChildsList;
						   if(jobChildsList.length>0){
							var str = "<tr style='background-color: pink'>"+
							"<td colspan='2' style='background-color: pink'><strong>子任务编码</strong></td>"+
							"<td  colspan='2' style='background-color: pink'><strong>子任务名称</strong></td>"+
							"<td  style='background-color: pink'><strong>子任务执行方式</strong></td>"+
						/* 	"<td  style='background-color: pink'><strong>子任务处理类</strong></td>"+ */
							"<td  style='background-color: pink'><strong>子任务参数</strong></td>"+
							"<td  style='background-color: pink'><strong>子任务周期</strong></td>"+
							"<td  style='background-color: pink'><strong>配置是否有效</strong></td>"+
                      /* 	"<td  style='background-color: pink'><strong>最大重执行次数</strong></td>"+ */
							"<td colspan='2' style='background-color: pink'><strong>操作</strong></td></tr>";
							str = str+showJobChildsList(jobChildsList);
							$("#"+job_code).html(str);
						   }
						}
					}
				  }); 
			 
		}
		
		
		function showJobChildsList(strJson){
			var str =""
			var j=strJson.length;
			 for(var i=0;i<j;i++){
				 var sub_job_code = strJson[i].sub_job_code !=null ? strJson[i].sub_job_code :''; //子任务编码
				 var job_name = strJson[i].job_name !=null ? strJson[i].job_name :'';             //任务名称
				 var exec_mode = strJson[i].exec_mode !=null ? strJson[i].exec_mode :'';          //执行周期
				 var job_classname = strJson[i].job_classname !=null ? strJson[i].job_classname :''; //任务处理类
				 var job_param = strJson[i].job_param !=null ? strJson[i].job_param :'';             //任务参数
				 var job_cron = strJson[i].job_cron !=null ? strJson[i].job_cron :'';                //任务周期
				 var job_valid = strJson[i].job_valid !=null ? strJson[i].job_valid :'';                //配置是否有效
				 var retry_num = strJson[i].retry_num !=null ? strJson[i].retry_num :'';                //最大重执行数
				 var jobconfig_id = strJson[i].jobconfig_id !=null ? strJson[i].jobconfig_id :'';                //自增id
				 if(exec_mode =="0"){
					 exec_mode ="周期执行";
				 }else if(exec_mode == "1"){
					 exec_mode ="非周期执行";
				 }
				 
				 if(job_valid =="0"){
					 job_valid ="无效";
				 }else if(job_valid == "1"){
					 job_valid ="有效";
				 }
				 str=str+
				    "<tr style='background-color: azure'>"+
					"<td colspan='2'>"+sub_job_code+"</td>"+
					"<td colspan='2'>"+job_name+"</td>"+
					"<td>"+exec_mode+"</td>"+
				/* 	"<td>"+job_classname+"</td>"+ */
					"<td>"+job_param+"</td>"+
					"<td>"+job_cron+"</td>"+
					"<td>"+job_valid+"</td>"+
				/* 	"<td>"+retry_num+"</td>"+ */
					"<td colspan='2'><div class='hidden-sm hidden-xs action-buttons' align='right'>"+
					"<a title='编辑' class='green' href='#' onclick='updateJob("+jobconfig_id+");' role='button' data-target='#myModal' data-toggle='modal'>"+
					"<i class='ace-icon fa fa-pencil bigger-130'></i></a>"+ 
					"<a title='删除' class='red' onClick='deleteJobConfig("+jobconfig_id+");'> <i class='ace-icon fa fa-trash-o bigger-130'></i></a></div></td></tr>";
		      
		     
			 }
			  return str;			
	  }
		 
		
	function updateJob(id){
		  $.ajax({
			    url : joblistcontext+'/backJobConfig/jobEdit?jobconfig_id='+id,
				type : "GET",
				success:function(data) {
					console.log(data);
					if(data.sessionStatus==540){//异步请求session过期状态
						window.location.href=joblistcontext+"/login";
						//location.href="show_product?prodId="+prod_id+"&sceneryName="+tdSceneryName+"&pageNum="+$("#pageNum").val();
					}else if(data.code=1){
						var jobConfigVO = data.jobConfigVO;
						$("#myModal").modal("show");
						$('#syscode').val(jobConfigVO.syscode);
						$('#job_code').val(jobConfigVO.job_code);
						$('#job_type').find("option[value="+jobConfigVO.job_type+"]").attr("selected",true);
						$('#job_seq').val(jobConfigVO.job_seq);
						$('#sub_job_code').val(jobConfigVO.sub_job_code);
						$('#job_name').val(jobConfigVO.job_name);
						$('#exec_mode').find("option[value="+jobConfigVO.exec_mode+"]").attr("selected",true);
						$('#job_classname').val(jobConfigVO.job_classname);
						$('#job_param').val(jobConfigVO.job_param);
						$('#job_cron').val(jobConfigVO.job_cron);
						$('#job_valid').find("option[value="+jobConfigVO.job_valid+"]").attr("selected",true);
						$('#retry_num').val(jobConfigVO.retry_num); 
						$('#convert_retry_num').val(jobConfigVO.convert_retry_num);
						$('#jobconfig_id').val(jobConfigVO.jobconfig_id);
						$('#syscode').attr({ readonly: 'true' }); 
						$('#job_code').attr({ readonly: 'true' }); 
						$('#job_type').attr({ readonly: 'true' }); 
						$('#job_seq').attr({ readonly: 'true' }); 
						$('#sub_job_code').attr({ readonly: 'true' }); 
						$('#job_name').attr({ readonly: 'true' }); 
						$('#exec_mode').attr({ readonly: 'true' }); 
						
						
						
						
					}
				}
			  }); 
		 
	}	
	
	
	  function deleteJobConfig(jobconfig_id){
		   bootbox.confirm("<strong style='font-size:15px;padding-left:200px'>确认删除该条数据吗？</strong>", function(result){
		   if(result){
		   $.ajax({
				url : joblistcontext+'/backJobConfig/jobConfigDelete?jobconfig_id='+jobconfig_id,
				type : "GET",
				success:function(data) {
					console.log(data);
					if(data.sessionStatus==540){//异步请求session过期状态
						window.location.href=configlistcontext+"/login";
					}else if(data.code=="0"){
						bootbox.alert("<strong style='font-size:15px;padding-left:200px'>数据删除失败！</strong>", function(){window.location.reload() ; });
					}else{
						bootbox.alert("<strong style='font-size:15px;padding-left:200px'>数据删除成功！</strong>", function(){window.location.reload() ; });
					}
					
				}
			  }); 
			}
		}); 
	  }

	

		
	</script>
</body>
</html>